    <div class="nav-sub w1180">
    	<ul class="zoom">
    		<li><a class="on" href="/crm/voucher/index">优惠券管理</a></li>
    	</ul>
    </div>
    <div class="main-ct w1180">
<!-- 		<a href="/crm/voucher" class="btn-cs btn-blue btn-fillet mt10">返 回</a> -->
		
    	<div class="Tcols clear">
    		<div class="fl form-info mt20" style="width:500px ">
        		<form id="form1" method="post" action="/crm/voucher/insert-voucher">
        		<input name="vt_id" id="vt_id" type="hidden" value="<?php echo $this->vt_id;?>">
        		<dl>
        			<dt>代金券名称：</dt>
        			<dd><input name="name" id="name" type="text" class="txt txt-ss" value="<?php echo isset($this->voucherType['vt_name'])?$this->voucherType['vt_name']:'';?>"></dd>
        		</dl>
        		<dl>
        			<dt>代金券金额：</dt>
        			<dd><input name="price" id="price" type="text" class="txt txt-ss" value="<?php echo isset($this->voucherType['vt_price'])?$this->voucherType['vt_price']:'';?>"></dd>
        		</dl>
        		<dl>
        			<dt>数量：</dt>
        			<dd><input name="num" id="num" type="text" class="txt txt-ss" <?php if($this->vt_id == ''):?>class="txt" <?php else:?> class="txt-custom" readonly="readonly" <?php endif;?> value="<?php echo isset($this->voucherType['vt_num'])?$this->voucherType['vt_num']:'';?>"></dd>
        		</dl>
        		<dl>
        			<dt>开始时间：</dt>
        			<dd><input name="start_time" id="start_time" type="text" class="txt txt-ss" onFocus="WdatePicker({isShowClear:false,readOnly:true})" value="<?php echo isset($this->voucherType['vt_start_time'])?$this->voucherType['vt_start_time']:'';?>"></dd>
        		</dl>
        		<dl>
        			<dt>截止时间：</dt>
        			<dd><input name="end_time" id="end_time" type="text" class="txt txt-ss" onFocus="WdatePicker({isShowClear:false,readOnly:true})" value="<?php echo isset($this->voucherType['vt_end_time'])?$this->voucherType['vt_end_time']:'';?>"></dd>
        		</dl>
        		<dl>
        			<dt>适用商家：</dt>
        			<dd><select class="category-select txt-ss" id="org_id" name="org_id">
    					<option value="">请选择</option>
    					<?php foreach ($this->organization as $organization):?>
    					<option value="<?php echo $organization['org_id'];?>" <?php if($this->vt_id != '' && $this->voucherType['org_id'] == $organization['org_id']):?>selected<?php endif;?>><?php echo $organization['org_name'];?></option>
    					<?php endforeach;?>
    				</select></dd>
        		</dl>
        		<dl>
        			<dt>适用商品：</dt>
        			<dd><select class="category-select txt-ss" id="product_id" name="product_id">
                        <option value="">请选择</option>
                        <?php foreach ($this->productList as $product):?>
                        <option value="<?php echo $product['product_id'];?>" <?php if($this->vt_id != '' && $this->voucherType['product_id'] == $product['product_id']):?>selected<?php endif;?>><?php echo $product['product_name'];?></option>
                        <?php endforeach;?>
    				</select></dd>
        		</dl>
        		
        		<dl>
        			<dt>订单限制金额：</dt>
        			<dd><input name="limit_price" id="limit_price" type="text" class="txt txt-ss" value="<?php echo isset($this->voucherType['vt_limit_price'])?$this->voucherType['vt_limit_price']:'';?>"></dd>
        		</dl>
        		
        		<dl>
        			<dt>备注：</dt>
        			<dd><input name="remark" id="remark" type="text" class="txt txt-ss" value="<?php echo isset($this->voucherType['vt_remark'])?$this->voucherType['vt_remark']:'';?>"></dd>
        		</dl>
				<dl>
					<dt>&nbsp;</dt>
					<dd>
						<input style="padding:5px;" class="input-cs btn-cs btn-yel mr10" type="submit" value="<?php echo $this->vt_id == ''? '生成' : '保存';?>">
						<?php if($this->vt_id != ''):?><a href="/crm/voucher/excel-detail/<?php echo $this->vt_id;?>" class="btn-cs btn-green" >输出报表</a><?php endif;?>
					</dd>
				</dl>
				</form>
        	</div>
        	<?php if($this->vt_id != ''):?>
    		<div class="fr list-fr">
    			<h1 class="tit-r">优惠券列表</h1>
    			<div class="row" id="list_table">
    			</div>
    		</div>
    		<?php endif;?>
    	</div>
	</div>
<script src="/plugins/My97DatePicker/WdatePicker.js"></script>
<script>
$().ready(function() {
	$("#form1").validate({
		debug:true,
		rules: {
			name: {
				required: true,
			},
			price: {
				required: true,
			},
			num: {
				required: true,
			},
			start_time: {
				required: true,
				dateISO: true,
			},
			end_time: {
				required: true,
				dateISO: true,
			},
			limit_price: {
				required: true,
			},
	
		},
		submitHandler:function(form){  
            form.submit();
	    }
	});

});

<?php if($this->vt_id != ''):?>
var page;

$(document).ready(function(){
	ajaxListTable();
});

function search(){
	page = 0;

	ajaxListTable();
}

function ajaxListTable(){
	$.ajax({
        type: "post",
        url : "<?php echo $this->url('crm/voucher',
            array('action'=>'ajax-voucher-list'));?>",
        dataType:'html',
        data:  { 
            "vt_id": '<?php echo $this->voucherType["vt_id"];?>', 
			"page":page },
        cache: false,
        timeout:10000, 
        error: function(){
          	 alert('请求超时，请重新操作');
             return false; 
         }, 
        success: function(html){
        	$("#list_table").html(html);
        }
    });
}
<?php endif;?>

$('#org_id').change(function(){
	$.ajax({
        type: "post",
        url : "<?php echo $this->url('crm/voucher',
            array('action'=>'ajax-product-list'));?>",
        dataType:'html',
        data:  { 
            "org_id": $('#org_id').val(), 
            "product_id": '<?php echo isset($this->voucherType['product_id'])?$this->voucherType['product_id']:'';?>'
			},
        cache: false,
        timeout:10000, 
        error: function(){
          	 alert('请求超时，请重新操作');
             return false; 
         }, 
        success: function(html){
        	$('#product_id').empty(); 
        	$('#product_id').append(html);
        }
    });

});

</script>
